﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{

    /// <summary>
    /// 各种污染物和不同类型降雨（固态、液态）的去除系数。
    /// CALPUFF GUI中包含了常用污染物的干湿沉积参数，，需提供这些参数作为默认
    /// </summary>
    public class PG10:Group
    {

        public PG10()
        {
            Param.Add(new WetParam("SO2", .00003, 0));
            Param.Add(new WetParam("NOX", 0, 0));
            Param.Add(new WetParam("HNO3", .00006, 0));
            Param.Add(new WetParam("NO", 0, 0));
            Param.Add(new WetParam("NO2", 0, 0));
            Param.Add(new WetParam("ODOR", 0, 0));
            Param.Add(new WetParam("TOLUENE", 0, 0));
            Param.Add(new WetParam("XYLENE", 0, 0));
            Param.Add(new WetParam("B-PINENE", 0, 0));
            Param.Add(new WetParam("A-PINENE", 0, 0));
            Param.Add(new WetParam("SO4", .0001, .00003));
            Param.Add(new WetParam("NO3", .0001, .00003));
            Param.Add(new WetParam("PM10", .0001, .00003));
            Param.Add(new WetParam("SOA", .0001, .00003));
            Param.Add(new WetParam("H2O", 0, 0));
            Param.Add(new WetParam("TXS", 0, 0));
            Param[0].CalculateSpecies = true;

        }


        /// <summary>
        /// 污染物和不同类型降雨（固态、液态）的去除系数。
        /// </summary>
        List<WetParam> m_Param = new List<WetParam>();

        public List<WetParam> Param
        {
            get { return m_Param; }
            set { m_Param = value; }
        }
        public override string WriteToGroup()
        {
            string Subgroup = "", TempStr;

            TempStr = StrWriter.GetCLine();
            TempStr += "INPUT GROUP: 10 -- Wet Deposition Parameters" + "\r\n";
            Subgroup += TempStr;

            TempStr = StrWriter.GetCLine();
            Subgroup += TempStr;

            //进行排序
            List<string> arry = Sort.GetPollutantRightOrder();
            List<WetParam> arryWetParam = new List<WetParam>();
            arryWetParam.Clear();
            foreach (string a in arry)
            {
                for (int i = 0; i < Param.Count; i++)
                {
                    if (a == Param[i].SPECNAM)
                    {
                        arryWetParam.Add(Param[i]);
                    }
                }
            }
            //---------------------------------------

            if (arryWetParam.Count > 0)
            {
                for (int i = 0; i < arryWetParam.Count; i++)
                {
                    if (arryWetParam[i].CalculateSpecies)
                    {
                        if (arryWetParam[i].IsWet)
                        {
                            TempStr = "!       " + arryWetParam[i].SPECNAM + "   =   " + arryWetParam[i].LIQUID.ToString() + ",   " + arryWetParam[i].FROZEN.ToString() + "   !" + "\r\n";
                            Subgroup += TempStr;
                        }
                    }
                }
            }
            Subgroup += "! END !" + "\r\n";
            return Subgroup;
        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            foreach (KeyValuePair<string, string> m_dic in dic)
            {

                WetParam ps = new WetParam("XX", 1, 1);

                this.Param.Add(ps.ReadFromGroup(m_dic.Key, m_dic.Value));


            }

        }



    }



    /// <summary>
    /// 污染物对于液体和冻态降雨的清除系数
    /// </summary>
    [Serializable]
    public class WetParam : ICloneable
    {
        public WetParam(string Name, double mLIQUID, double mFROZEN)
        {
            this.SPECNAM = Name;
            this.LIQUID = mLIQUID;
            this.FROZEN = mFROZEN;
        }
        /// <summary>
        /// 污染物名称
        /// </summary>
        string m_SPECNAM = "";
        /// <summary>
        /// 污染物名称
        /// </summary>
        public string SPECNAM
        {
            get { return m_SPECNAM; }
            set { m_SPECNAM = value; }
        }
        /// <summary>
        ///液态降雨湿沉降系数
        /// </summary>
        double m_LIQUID = 0;
        /// <summary>
        ///液态降雨湿沉降系数
        /// </summary>
        public double LIQUID
        {
            get { return m_LIQUID; }
            set { m_LIQUID = value; }
        }
        /// <summary>
        /// 固态降雨湿沉降系数
        /// </summary>
        double m_FROZEN = 0;
        /// <summary>
        /// 固态降雨湿沉降系数
        /// </summary>
        public double FROZEN
        {
            get { return m_FROZEN; }
            set { m_FROZEN = value; }
        }
        private bool m_CalculateSpecies = false;
        /// <summary>
        /// 是否估算污染物
        /// </summary>
        public bool CalculateSpecies
        {
            get { return m_CalculateSpecies; }
            set { m_CalculateSpecies = value; }
        }

        private bool m_IsWet = false;
        /// <summary>
        /// 是否是湿沉积，默认为否
        /// </summary>
        public bool IsWet
        {
            get { return m_IsWet; }
            set { m_IsWet = value; }
        }

        public WetParam ReadFromGroup(string name, string str)
        {
            WetParam ps = new WetParam("XX", 1, 1);

            ps.SPECNAM = name;
            ps.LIQUID = Convert.ToDouble(StrWriter.GetString(str, 1));
            ps.FROZEN = Convert.ToDouble(StrWriter.GetString(str, 2));

            return ps;
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }




}
